package files;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketOptions;
import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Set;

public class FileClient {
    public static void main(String[] args) throws IOException, InterruptedException {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                SocketChannel socketChannel = null;
                int i=0;
                try {
                    socketChannel = SocketChannel.open();
                    socketChannel.configureBlocking(true);
                    socketChannel.connect(new InetSocketAddress("192.168.31.71", 8080));
                    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4096);
                    socketChannel.setOption(StandardSocketOptions.TCP_NODELAY,true);

                    while (true) {
                        i++;
                        byteBuffer.clear();
                        byteBuffer.put("1".getBytes());
                        byteBuffer.flip();
                        socketChannel.write(byteBuffer);
                        if (i > 100) {
                            break;
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        socketChannel.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        thread.join();
        thread.start();
    }
}
